home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gpp-1_42.lha / g++-1.42.0 / toplev.c < prev    next >
C/C++ Source or Header  |  1992-07-13  |  63KB  |  2,439 lines

  1. /* Top level of GNU C compiler
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This is the top level of cc1/c++.
  22.    It parses command args, opens files, invokes the various passes
  23.    in the proper order, and counts the time used by each.
  24.    Error messages and low-level interface to malloc also handled here.  */
  25.  
  26. #include "config.h"
  27. #include <sys/types.h>
  28. #include <stdio.h>
  29. #include <signal.h>
  30. #include <setjmp.h>
  31.  
  32. #include <sys/stat.h>
  33. #include <sys/file.h>
  34.  
  35. /* Define getpagesize () if the system does not.  */
  36. #include "getpagesize.h"
  37.  
  38. #ifdef NO_UNISTD_H
  39. #define SEEK_SET L_SET
  40. #define SEEK_CUR L_INCR
  41. #define SEEK_END L_XTND
  42. #else
  43. #include <unistd.h>
  44. #endif
  45.  
  46. #ifdef USG
  47. #include <sys/fcntl.h>
  48. #undef FLOAT
  49. #include <sys/param.h>
  50. /* This is for hpux.  It is a real screw.  They should change hpux.  */
  51. #undef FLOAT
  52. #include <sys/times.h>
  53. #include <time.h>   /* Correct for hpux at least.  Is it good on other USG?  */
  54. #undef FFS  /* Some systems define this in param.h.  */
  55. #else
  56. #ifndef VMS
  57. #include <sys/time.h>
  58. #include <sys/resource.h>
  59. #endif
  60. #endif
  61.  
  62. #include "input.h"
  63. #include "tree.h"
  64. #include "c-tree.h"
  65. #include "rtl.h"
  66. #include "flags.h"
  67.  
  68. #ifndef Z_BUFSIZ
  69. #define Z_BUFSIZ(p) ((p)->_bufsiz)
  70. #endif
  71.  
  72. /* Change by Bryan Boreham, Kewill, Sun Jul 23 14:41:26 1989.
  73.    Added some stuff for unexec-ing a part-done compilation. */
  74.  
  75. int been_here_before = 0;    /* Is this an unexec'd program? */
  76. int just_done_unexec = 0;    /* Is this the process that *was* unexec'd?  */
  77. char *dump_source_name;        /* Keep argv[0] for dumping. */
  78.  
  79. /* @@ Should there be a filename length limit?  */
  80. char previous_asm_file_name[128]; /* asm_file_name from the first run. */
  81.  
  82. extern int yydebug;
  83.  
  84. extern FILE *finput;
  85.  
  86. extern int reload_completed;
  87. extern int rtx_equal_function_value_matters;
  88.  
  89. extern void init_lex ();
  90. extern void init_decl_processing ();
  91. extern void init_tree ();
  92. extern void init_rtl ();
  93. extern void init_optabs ();
  94. extern void init_stmt ();
  95. extern void init_reg_sets ();
  96. extern void dump_flow_info ();
  97. extern void dump_local_alloc ();
  98.  
  99. void rest_of_decl_compilation ();
  100. void error ();
  101. void error_with_file_and_line ();
  102. void fancy_abort ();
  103. void set_target_switch ();
  104. void print_target_switch_defaults ();
  105. static char *decl_name ();
  106.  
  107. /* Bit flags that specify the machine subtype we are compiling for.
  108.    Bits are tested using macros TARGET_... defined in the tm-...h file
  109.    and set by `-m...' switches.  */
  110.  
  111. int target_flags;
  112.  
  113. /* Name of current original source file (what was input to cpp).
  114.    This comes from each #-command in the actual input.  */
  115.  
  116. char *input_filename;
  117.  
  118. /* Name of top-level original source file (what was input to cpp).
  119.    This comes from the #-command at the beginning of the actual input.
  120.    If there isn't any there, then this is the cc1 input file name.  */
  121.  
  122. char *main_input_filename;
  123.  
  124. /* Current line number in real source file.  */
  125.  
  126. int lineno;
  127.  
  128. /* Stack of currently pending input files.  */
  129.  
  130. struct file_stack *input_file_stack;
  131.  
  132. /* Incremented on each change to input_file_stack.  */
  133. int input_file_stack_tick;
  134.  
  135. /* FUNCTION_DECL for function now being parsed or compiled.  */
  136.  
  137. extern tree current_function_decl;
  138.  
  139. /* Name to use as base of names for dump output files.  */
  140.  
  141. char *dump_base_name;
  142.  
  143. /* Flags saying which kinds of debugging dump have been requested.  */
  144.  
  145. int rtl_dump = 0;
  146. int rtl_dump_and_exit = 0;
  147. int jump_opt_dump = 0;
  148. int cse_dump = 0;
  149. int loop_dump = 0;
  150. int flow_dump = 0;
  151. int combine_dump = 0;
  152. int local_reg_dump = 0;
  153. int global_reg_dump = 0;
  154. int jump2_opt_dump = 0;
  155. int dbr_sched_dump = 0;
  156.  
  157. /* 1 => write gdb debugging output (using symout.c).  -g0
  158.    2 => write dbx debugging output (using dbxout.c).  -G0  */
  159.  
  160. enum debugger write_symbols = NO_DEBUG;
  161.  
  162. /* Nonzero means can use our own extensions to DBX format.
  163.    Relevant only with write_symbols == DBX_DEBUG.  */
  164.  
  165. int use_gdb_dbx_extensions;
  166.  
  167. /* Nonzero means do optimizations.  -opt.  */
  168.  
  169. int optimize = 0;
  170.  
  171. /* Nonzero means `char' should be signed.  */
  172.  
  173. int flag_signed_char;
  174.  
  175. /* Nonzero means give an enum type only as many bytes as it needs.  */
  176.  
  177. int flag_short_enums;
  178.  
  179. /* Nonzero for -fcaller-saves: allocate values in regs that need to
  180.    be saved across function calls, if that produces overall better code.
  181.    Optional now, so people can test it.  */
  182.  
  183. #ifdef DEFAULT_CALLER_SAVES
  184. int flag_caller_saves = 1;
  185. #else
  186. int flag_caller_saves = 0;
  187. #endif
  188.  
  189. /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
  190.  
  191. int flag_pcc_struct_return = 0;
  192.  
  193. /* Nonzero for -fforce-mem: load memory value into a register
  194.    before arithmetic on it.  This makes better cse but slower compilation.  */
  195.  
  196. int flag_force_mem = 0;
  197.  
  198. /* Nonzero for -fforce-addr: load memory address into a register before
  199.    reference to memory.  This makes better cse but slower compilation.  */
  200.  
  201. int flag_force_addr = 0;
  202.  
  203. /* Nonzero for -fdefer-pop: don't pop args after each function call;
  204.    instead save them up to pop many calls' args with one insns.  */
  205.  
  206. int flag_defer_pop = 1;
  207.  
  208. /* Nonzero for -ffloat-store: don't allocate floats and doubles
  209.    in extended-precision registers.  */
  210.  
  211. int flag_float_store = 0;
  212.  
  213. /* Nonzero for -fcombine-regs:
  214.    allow instruction combiner to combine an insn
  215.    that just copies one reg to another.  */
  216.  
  217. int flag_combine_regs = 0;
  218.  
  219. /* Nonzero enables strength-reduction in loop.c.  */
  220.  
  221. int flag_strength_reduce = 0;
  222.  
  223. /* Nonzero for -fwritable-strings:
  224.    store string constants in data segment and don't uniquize them.  */
  225.  
  226. int flag_writable_strings = 0;
  227.  
  228. /* Nonzero means don't put addresses of constant functions in registers.
  229.    Used for compiling the Unix kernel, where strange substitutions are
  230.    done on the assembly output.  */
  231.  
  232. int flag_no_function_cse = 0;
  233.  
  234. /* Nonzero for -fomit-frame-pointer:
  235.    don't make a frame pointer in simple functions that don't require one.  */
  236.  
  237. int flag_omit_frame_pointer = 0;
  238.  
  239. /* Nonzero to inhibit use of define_optimization peephole opts.  */
  240.  
  241. int flag_no_peephole = 0;
  242.  
  243. /* Nonzero means all references through pointers are volatile.  */
  244.  
  245. int flag_volatile;
  246.  
  247. /* Nonzero means just do syntax checking; don't output anything.  */
  248.  
  249. int flag_syntax_only = 0;
  250.  
  251. /* Nonzero means do stupid register allocation.  -noreg.
  252.    This and `optimize' are controlled by different switches in cc1,
  253.    but normally cc controls them both with the -O switch.  */
  254.  
  255. int obey_regdecls = 0;
  256.  
  257. /* Don't print functions as they are compiled and don't print
  258.    times taken by the various passes.  -quiet.  */
  259.  
  260. int quiet_flag = 0;
  261.  
  262. /* Don't print warning messages.  -w.  */
  263.  
  264. int inhibit_warnings = 0;
  265.  
  266. /* Do print extra warnings (such as for uninitialized variables).  -W.  */
  267.  
  268. int extra_warnings = 0;
  269.  
  270. /* Nonzero to warn about unused local variables.  */
  271.  
  272. int warn_unused;
  273.  
  274. /* Nonzero means warn about all declarations which shadow others.   */
  275.  
  276. int warn_shadow;
  277.  
  278. /* Warn if a switch on an enum fails to have a case for every enum value.  */
  279.  
  280. int warn_switch;
  281.  
  282. /* Warn if a type conversion is done that might have confusing results.  */
  283.  
  284. int warn_conversion;
  285.  
  286. /* Nonzero means warn about any identifiers that match in the first N
  287.    characters.  The value N is in `id_clash_len'.  */
  288.  
  289. int warn_id_clash;
  290. int id_clash_len;
  291.  
  292. /* Nonzero means warn if inline function is too large.  */
  293.  
  294. int warn_inline;
  295.  
  296. /* Number of error messages and warning messages so far.  */
  297.  
  298. int errorcount = 0;
  299. int warningcount = 0;
  300. int sorrycount = 0;
  301.  
  302. /* Pointer to function to compute the name to use to print a declaration.  */
  303.  
  304. char *(*decl_printable_name) ();
  305.  
  306. /* Pointer to function to compute rtl for a language-specific tree code.  */
  307.  
  308. struct rtx_def *(*lang_expand_expr) ();
  309.  
  310. /* Name of program invoked, sans directories.  */
  311.  
  312. char *progname;
  313.  
  314. /* Nonzero if generating code to do profiling.  */
  315.  
  316. int profile_flag = 0;
  317.  
  318. /* Nonzero if generating code to do profiling on a line-by-line basis.  */
  319.  
  320. int profile_block_flag;
  321.  
  322. /* Nonzero for -pedantic switch: warn about anything
  323.    that standard spec forbids.  */
  324.  
  325. int pedantic = 0;
  326.  
  327. /* Nonzero for -finline-functions: ok to inline functions that look like
  328.    good inline candidates.  */
  329.  
  330. int flag_inline_functions;
  331.  
  332. /* Nonzero for -fkeep-inline-functions: even if we make a function
  333.    go inline everywhere, keep its defintion around for debugging
  334.    purposes.  */
  335.  
  336. int flag_keep_inline_functions;
  337.  
  338. /* Nonzero means make the text shared if supported.  */
  339.  
  340. int flag_shared_data;
  341.  
  342. /* Nonzero means schedule into delayed branch slots if supported.  */
  343.  
  344. int flag_delayed_branch;
  345.  
  346. /* Copy of arguments to main.  */
  347. int save_argc;
  348. char **save_argv;
  349.  
  350. /* Nonzero means schedule instructions within basic blocks.  */
  351.  
  352. int flag_schedule_insns = 0;
  353.  
  354. /* Name for output file of assembly code, specified with -o.  */
  355.  
  356. char *asm_file_name;
  357.  
  358. #if 0
  359. /* Name for output file of GDB symbol segment, specified with -symout.  */
  360.  
  361. char *sym_file_name;
  362. #endif /* 0 */
  363.  
  364. #ifdef G_SWITCH
  365. /* Value of the -G nn switch if the machine needs it.  */
  366.  
  367. int g_switch_value = 0;
  368. int g_switch_used = 0;
  369. #endif
  370.  
  371. /* Table of language-independent -f options.
  372.    STRING is the option name.  VARIABLE is the address of the variable.
  373.    ON_VALUE is the value to store in VARIABLE
  374.     if `-fSTRING' is seen as an option.
  375.    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
  376.  
  377. struct { char *string; int *variable; int on_value;} f_options[] =
  378. {
  379.   {"float-store", &flag_float_store, 1},
  380.   {"volatile", &flag_volatile, 1},
  381.   {"defer-pop", &flag_defer_pop, 1},
  382.   {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
  383.   {"strength-reduce", &flag_strength_reduce, 1},
  384.   {"writable-strings", &flag_writable_strings, 1},
  385.   {"peephole", &flag_no_peephole, 0},
  386.   {"force-mem", &flag_force_mem, 1},
  387.   {"force-addr", &flag_force_addr, 1},
  388.   {"combine-regs", &flag_combine_regs, 1},
  389.   {"function-cse", &flag_no_function_cse, 0},
  390.   {"inline-functions", &flag_inline_functions, 1},
  391.   {"keep-inline-functions", &flag_keep_inline_functions, 1},
  392.   {"syntax-only", &flag_syntax_only, 1},
  393.   {"shared-data", &flag_shared_data, 1},
  394.   {"caller-saves", &flag_caller_saves, 1},
  395.   {"pcc-struct-return", &flag_pcc_struct_return, 1},
  396.   {"delayed-branch", &flag_delayed_branch, 1},
  397.   {"schedule-insns", &flag_schedule_insns, 1}
  398. };
  399.  
  400. /* Output files for assembler code (real compiler output)
  401.    and debugging dumps.  */
  402.  
  403. FILE *asm_out_file;
  404. FILE *rtl_dump_file;
  405. FILE *jump_opt_dump_file;
  406. FILE *cse_dump_file;
  407. FILE *loop_dump_file;
  408. FILE *flow_dump_file;
  409. FILE *combine_dump_file;
  410. FILE *local_reg_dump_file;
  411. FILE *global_reg_dump_file;
  412. FILE *jump2_opt_dump_file;
  413. FILE *dbr_sched_dump_file;
  414.  
  415. /* Time accumulators, to count the total time spent in various passes.  */
  416.  
  417. int parse_time;
  418. int varconst_time;
  419. int integration_time;
  420. int jump_time;
  421. int cse_time;
  422. int loop_time;
  423. int flow_time;
  424. int combine_time;
  425. int local_alloc_time;
  426. int global_alloc_time;
  427. int dbr_sched_time;
  428. int final_time;
  429. int symout_time;
  430. int dump_time;
  431.  
  432. #ifdef FIELD_XREF
  433.   int field_xref = 0;        /* cross referencing flag    */
  434. #endif
  435.  
  436. /* Return time used so far, in microseconds.  */
  437.  
  438. int
  439. gettime ()
  440. {
  441. #ifdef USG
  442.   struct tms tms;
  443. #else
  444. #ifndef VMS
  445.   struct rusage rusage;
  446. #else /* VMS */
  447.   struct
  448.     {
  449.       int proc_user_time;
  450.       int proc_system_time;
  451.       int child_user_time;
  452.       int child_system_time;
  453.     } vms_times;
  454. #endif
  455. #endif
  456.  
  457.   if (quiet_flag)
  458.     return 0;
  459.  
  460. #ifdef USG
  461.   times (&tms);
  462.   return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
  463. #else
  464. #ifndef VMS
  465.   getrusage (0, &rusage);
  466.   return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
  467.       + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
  468. #else /* VMS */
  469.   times (&vms_times);
  470.   return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
  471. #endif
  472. #endif
  473. }
  474.  
  475. #define TIMEVAR(VAR, BODY)    \
  476. do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
  477.  
  478. void
  479. print_time (str, total)
  480.      char *str;
  481.      int total;
  482. {
  483.   fprintf (stderr,
  484.        "time in %s: %d.%06d\n",
  485.        str, total / 1000000, total % 1000000);
  486. }
  487.  
  488. /* Count an error or warning.  Return 1 if the message should be printed.  */
  489.  
  490. int
  491. count_error (warningp)
  492.      int warningp;
  493. {
  494.   if (warningp && inhibit_warnings)
  495.     return 0;
  496.  
  497.   if (warningp)
  498.     warningcount++;
  499.   else
  500.     errorcount++;
  501.  
  502.   return 1;
  503. }
  504.  
  505. /* Print a fatal error message.  NAME is the text.
  506.    Also include a system error message based on `errno'.  */
  507.  
  508. void
  509. pfatal_with_name (name)
  510.      char *name;
  511. {
  512.   fprintf (stderr, "%s: ", progname);
  513.   perror (name);
  514.   exit (35);
  515. }
  516.  
  517. void
  518. fatal_io_error (name)
  519.      char *name;
  520. {
  521.   fprintf (stderr, "%s: %s: I/O error\n", progname, name);
  522.   exit (35);
  523. }
  524.  
  525. void
  526. fatal (s, v)
  527.      char *s;
  528.      int v;
  529. {
  530.   error (s, v);
  531.   exit (34);
  532. }
  533.  
  534. /* Called from insn-extract to give a better error message when we
  535.    don't have an insn to match what we are looking for, rather
  536.    than just calling abort().  */
  537.  
  538. void
  539. fatal_insn_not_found (insn)
  540.      rtx insn;
  541. {
  542.   error ("The following insn was not recognizable:", 0);
  543.   debug_rtx (insn);
  544.   abort ();
  545. }
  546.  
  547. /* This is the default decl_printable_name function.  */
  548.  
  549. static char *
  550. decl_name (decl)
  551.      tree decl;
  552. {
  553.   return IDENTIFIER_POINTER (DECL_NAME (decl));
  554. }
  555.  
  556. static int need_error_newline;
  557.  
  558. /* Function of last error message;
  559.    more generally, function such that if next error message is in it
  560.    then we don't have to mention the function name.  */
  561. static tree last_error_function = NULL;
  562.  
  563. /* Used to detect when input_file_stack has changed since last described.  */
  564. static int last_error_tick;
  565.  
  566. /* Called when the start of a function definition is parsed,
  567.    this function prints on stderr the name of the function.  */
  568.  
  569. void
  570. announce_function (decl)
  571.      tree decl;
  572. {
  573.   if (! quiet_flag)
  574.     {
  575.       if (rtl_dump_and_exit)
  576.     fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
  577.       else
  578.     fprintf (stderr, " %s", (*decl_printable_name) (decl));
  579.       fflush (stderr);
  580.       need_error_newline = 1;
  581.       last_error_function = current_function_decl;
  582.     }
  583. }
  584.  
  585. /* Prints out, if necessary, the name of the current function
  586.    which caused an error.  Called from all error and warning functions.  */
  587.  
  588. void
  589. report_error_function (file)
  590.      char *file;
  591. {
  592.   struct file_stack *p;
  593.  
  594.   if (need_error_newline)
  595.     {
  596.       fprintf (stderr, "\n");
  597.       need_error_newline = 0;
  598.     }
  599.  
  600.   if (last_error_function != current_function_decl)
  601.     {
  602.       if (file)
  603.     fprintf (stderr, "%s: ", file);
  604.  
  605.       if (current_function_decl == NULL)
  606.     fprintf (stderr, "At top level:\n");
  607.       else if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
  608.     fprintf (stderr, "In method %s:\n",
  609.          (*decl_printable_name) (current_function_decl));
  610.       else
  611.     fprintf (stderr, "In function %s:\n",
  612.          (*decl_printable_name) (current_function_decl));
  613.  
  614.       last_error_function = current_function_decl;
  615.     }
  616.   if (input_file_stack && input_file_stack->next != 0
  617.       && input_file_stack_tick != last_error_tick)
  618.     {
  619.       fprintf (stderr, "In file included");
  620.       for (p = input_file_stack->next; p; p = p->next)
  621.     {
  622.       fprintf (stderr, " from %s:%d", p->name, p->line);
  623.       if (p->next)
  624.         fprintf (stderr, ",");
  625.     }
  626.       fprintf (stderr, ":\n");
  627.       last_error_tick = input_file_stack_tick;
  628.     }
  629. }
  630.  
  631. /* Report an error at the current line number.
  632.    S and V are a string and an arg for `printf'.  */
  633.  
  634. void
  635. error (s, v, v2)
  636.      char *s;
  637.      int v;            /* @@also used as pointer */
  638.      int v2;            /* @@also used as pointer */
  639. {
  640.   error_with_file_and_line (input_filename, lineno, s, v, v2);
  641. }
  642.  
  643. /* Report an error at line LINE of file FILE.
  644.    S and V are a string and an arg for `printf'.  */
  645.  
  646. void
  647. error_with_file_and_line (file, line, s, v, v2)
  648.      char *file;
  649.      int line;
  650.      char *s;
  651.      int v;
  652.      int v2;
  653. {
  654.   count_error (0);
  655.  
  656.   report_error_function (file);
  657.  
  658.   if (file)
  659.     fprintf (stderr, "%s:%d: ", file, line);
  660.   else
  661.     fprintf (stderr, "%s: ", progname);
  662.   fprintf (stderr, s, v, v2);
  663.   fprintf (stderr, "\n");
  664. }
  665.  
  666. /* Report an error at the declaration DECL.
  667.    S and V are a string and an arg which uses %s to substitute the declaration name.  */
  668.  
  669. void
  670. error_with_decl (decl, s, v)
  671.      tree decl;
  672.      char *s;
  673.      int v;
  674. {
  675.   count_error (0);
  676.  
  677.   report_error_function (DECL_SOURCE_FILE (decl));
  678.  
  679.   if (TREE_CODE (decl) == PARM_DECL)
  680.     fprintf (stderr, "%s:%d: ",
  681.          DECL_SOURCE_FILE (DECL_CONTEXT (decl)),
  682.          DECL_SOURCE_LINE (DECL_CONTEXT (decl)));
  683.   else
  684.     fprintf (stderr, "%s:%d: ",
  685.          DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  686.  
  687.   if (DECL_NAME (decl))
  688.     fprintf (stderr, s, (*decl_printable_name) (decl), v);
  689.   else
  690.     fprintf (stderr, s, "((anonymous))", v);
  691.   fprintf (stderr, "\n");
  692. }
  693.  
  694. /* Report an error at the line number of the insn INSN.
  695.    S and V are a string and an arg for `printf'.
  696.    This is used only when INSN is an `asm' with operands,
  697.    and each ASM_OPERANDS records its own source file and line.  */
  698.  
  699. void
  700. error_for_asm (insn, s, v, v2)
  701.      rtx insn;
  702.      char *s;
  703.      int v;            /* @@also used as pointer */
  704.      int v2;            /* @@also used as pointer */
  705. {
  706.   rtx temp;
  707.   char *filename;
  708.   int line;
  709.   rtx body = PATTERN (insn);
  710.   rtx asmop;
  711.  
  712.   /* Find the (or one of the) ASM_OPERANDS in the insn.  */
  713.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  714.     asmop = SET_SRC (body);
  715.   else if (GET_CODE (body) == ASM_OPERANDS)
  716.     asmop = body;
  717.   else if (GET_CODE (body) == PARALLEL
  718.        && GET_CODE (XVECEXP (body, 0, 0)) == SET)
  719.     asmop = SET_SRC (XVECEXP (body, 0, 0));
  720.   else if (GET_CODE (body) == PARALLEL
  721.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  722.     asmop = XVECEXP (body, 0, 0);
  723.  
  724.   filename = ASM_OPERANDS_SOURCE_FILE (asmop);
  725.   line = ASM_OPERANDS_SOURCE_LINE (asmop);
  726.  
  727.   error_with_file_and_line (filename, line, s, v, v2);
  728. }
  729.  
  730. /* Report a warning at line LINE.
  731.    S and V are a string and an arg for `printf'.  */
  732.  
  733. void
  734. warning_with_file_and_line (file, line, s, v, v2)
  735.      char *file;
  736.      int line;
  737.      char *s;
  738.      int v;
  739.      int v2;
  740. {
  741.   if (count_error (1) == 0)
  742.     return;
  743.  
  744.   report_error_function (file);
  745.  
  746.   if (file)
  747.     fprintf (stderr, "%s:%d: ", file, line);
  748.   else
  749.     fprintf (stderr, "%s: ", progname);
  750.  
  751.   fprintf (stderr, "warning: ");
  752.   fprintf (stderr, s, v, v2);
  753.   fprintf (stderr, "\n");
  754. }
  755.  
  756. /* Report a warning at the current line number.
  757.    S and V are a string and an arg for `printf'.  */
  758.  
  759. void
  760. warning (s, v, v2)
  761.      char *s;
  762.      int v;            /* @@also used as pointer */
  763.      int v2;
  764. {
  765.   warning_with_file_and_line (input_filename, lineno, s, v, v2);
  766. }
  767.  
  768. /* Report a warning at the declaration DECL.
  769.    S is string which uses %s to substitute the declaration name.
  770.    V is a second parameter that S can refer to.  */
  771.  
  772. void
  773. warning_with_decl (decl, s, v)
  774.      tree decl;
  775.      char *s;
  776.      int v;
  777. {
  778.   if (count_error (1) == 0)
  779.     return;
  780.  
  781.   report_error_function (DECL_SOURCE_FILE (decl));
  782.  
  783.   if (TREE_CODE (decl) == PARM_DECL)
  784.     fprintf (stderr, "%s:%d: ",
  785.          DECL_SOURCE_FILE (DECL_CONTEXT (decl)),
  786.          DECL_SOURCE_LINE (DECL_CONTEXT (decl)));
  787.   else
  788.     fprintf (stderr, "%s:%d: ",
  789.          DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  790.  
  791.   fprintf (stderr, "warning: ");
  792.   if (DECL_NAME (decl))
  793.     fprintf (stderr, s, (*decl_printable_name) (decl), v);
  794.   else
  795.     fprintf (stderr, s, "((anonymous))", v);
  796.   fprintf (stderr, "\n");
  797. }
  798.  
  799. /* Report a warning at the line number of the insn INSN.
  800.    S and V are a string and an arg for `printf'.
  801.    This is used only when INSN is an `asm' with operands,
  802.    and each ASM_OPERANDS records its own source file and line.  */
  803.  
  804. void
  805. warning_for_asm (insn, s, v, v2)
  806.      rtx insn;
  807.      char *s;
  808.      int v;            /* @@also used as pointer */
  809.      int v2;            /* @@also used as pointer */
  810. {
  811.   char *filename;
  812.   int line;
  813.   rtx body = PATTERN (insn);
  814.   rtx asmop;
  815.  
  816.   /* Find the (or one of the) ASM_OPERANDS in the insn.  */
  817.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  818.     asmop = SET_SRC (body);
  819.   else if (GET_CODE (body) == ASM_OPERANDS)
  820.     asmop = body;
  821.   else if (GET_CODE (body) == PARALLEL
  822.        && GET_CODE (XVECEXP (body, 0, 0)) == SET)
  823.     asmop = SET_SRC (XVECEXP (body, 0, 0));
  824.   else if (GET_CODE (body) == PARALLEL
  825.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  826.     asmop = XVECEXP (body, 0, 0);
  827.  
  828.   filename = ASM_OPERANDS_SOURCE_FILE (asmop);
  829.   line = ASM_OPERANDS_SOURCE_LINE (asmop);
  830.  
  831.   warning_with_file_and_line (filename, line, s, v, v2);
  832. }
  833.  
  834. /* Apologize for not implementing some feature.
  835.    S, V, and V2 are a string and args for `printf'.  */
  836.  
  837. void
  838. sorry (s, v, v2)
  839.      char *s;
  840.      int v, v2;
  841. {
  842.   sorrycount++;
  843.   if (input_filename)
  844.     fprintf (stderr, "%s:%d: ", input_filename, lineno);
  845.   else
  846.     fprintf (stderr, "%s: ", progname);
  847.  
  848.   fprintf (stderr, "sorry, not implemented: ");
  849.   fprintf (stderr, s, v, v2);
  850.   fprintf (stderr, "\n");
  851. }
  852.  
  853. /* Apologize for not implementing some feature, then quit.
  854.    S, V, and V2 are a string and args for `printf'.  */
  855.  
  856. void
  857. really_sorry (s, v, v2)
  858.      char *s;
  859.      int v, v2;
  860. {
  861.   if (input_filename)
  862.     fprintf (stderr, "%s:%d: ", input_filename, lineno);
  863.   else
  864.     fprintf (stderr, "c++: ");
  865.  
  866.   fprintf (stderr, "sorry, not implemented: ");
  867.   fprintf (stderr, s, v, v2);
  868.   fatal (" (fatal)\n");
  869. }
  870.  
  871. /* More 'friendly' abort that prints the line and file.
  872.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  873.  
  874. void
  875. fancy_abort ()
  876. {
  877.   fatal ("Internal gcc abort.");
  878. }
  879.  
  880. /* When `malloc.c' is compiled with `rcheck' defined,
  881.    it calls this function to report clobberage.  */
  882.  
  883. void
  884. botch (s)
  885. {
  886.   abort ();
  887. }
  888.  
  889. /* Same as `malloc' but report error if no memory available.  */
  890.  
  891. int
  892. xmalloc (size)
  893.      unsigned size;
  894. {
  895.   register int value = (int) malloc (size);
  896.   if (value == 0)
  897.     fatal ("Virtual memory exhausted.");
  898.   return value;
  899. }
  900.  
  901. /* Same as `realloc' but report error if no memory available.  */
  902.  
  903. int
  904. xrealloc (ptr, size)
  905.      char *ptr;
  906.      int size;
  907. {
  908.   int result = realloc (ptr, size);
  909.   if (!result)
  910.     fatal ("Virtual memory exhausted.");
  911.   return result;
  912. }
  913.  
  914. /* Return the logarithm of X, base 2, considering X unsigned,
  915.    if X is a power of 2.  Otherwise, returns -1.  */
  916.  
  917. int
  918. exact_log2 (x)
  919.      register unsigned int x;
  920. {
  921.   register int log = 0;
  922.   /* Test for 0 or a power of 2.  */
  923.   if (x == 0 || x != (x & -x))
  924.     return -1;
  925.   while ((x >>= 1) != 0)
  926.     log++;
  927.   return log;
  928. }
  929.  
  930. /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
  931.    If X is 0, return -1.  */
  932.  
  933. int
  934. floor_log2 (x)
  935.      register unsigned int x;
  936. {
  937.   register int log = -1;
  938.   while (x != 0)
  939.     log++,
  940.     x >>= 1;
  941.   return log;
  942. }
  943.  
  944. int float_handled;
  945. jmp_buf float_handler;
  946. jmp_buf toplevel;
  947.  
  948. /* Specify where to longjmp to when a floating arithmetic error happens.
  949.    If HANDLER is 0, it means don't handle the errors any more.  */
  950.  
  951. void
  952. set_float_handler (handler)
  953.      jmp_buf handler;
  954. {
  955.   float_handled = (handler != 0);
  956.   if (handler)
  957.     bcopy (handler, float_handler, sizeof (float_handler));
  958. }
  959.  
  960. /* Signals actually come here.  */
  961.  
  962. static void
  963. float_signal ()
  964. {
  965.   if (float_handled == 0)
  966.     abort ();
  967.   float_handled = 0;
  968.   longjmp (float_handler, 1);
  969. }
  970.  
  971. /* Handler for SIGPIPE.  */
  972.  
  973. static void
  974. pipe_closed ()
  975. {
  976.   fatal ("output pipe has been closed");
  977. }
  978.  
  979. /* Compile an entire file of output from cpp, named NAME.
  980.    Write a file of assembly output and various debugging dumps.  */
  981.  
  982. static void
  983. compile_file (name)
  984.      char *name;
  985. {
  986.   tree globals;
  987.   int start_time;
  988.   int dump_base_name_length;
  989.  
  990.   int name_specified = name != 0;
  991.  
  992.   if (dump_base_name == 0 || been_here_before)
  993.     dump_base_name = name ? name : "gccdump";
  994.   dump_base_name_length = strlen (dump_base_name);
  995.  
  996.   parse_time = 0;
  997.   varconst_time = 0;
  998.   integration_time = 0;
  999.   jump_time = 0;
  1000.   cse_time = 0;
  1001.   loop_time = 0;
  1002.   flow_time = 0;
  1003.   combine_time = 0;
  1004.   local_alloc_time = 0;
  1005.   global_alloc_time = 0;
  1006.   dbr_sched_time = 0;
  1007.   final_time = 0;
  1008.   symout_time = 0;
  1009.   dump_time = 0;
  1010.  
  1011.   /* Open input file.  */
  1012.  
  1013.   if (name == 0 || !strcmp (name, "-"))
  1014.     {
  1015.       finput = stdin;
  1016.       name = "stdin";
  1017.     }
  1018.   else
  1019.     finput = fopen (name, "r");
  1020.   if (finput == 0)
  1021.     pfatal_with_name (name);
  1022.  
  1023.   /* Initialize data in various passes,  
  1024.      checking if this is an unexec'd program - bryan@kewill.uucp.  */
  1025.  
  1026.   if (!been_here_before)
  1027.     {
  1028.       init_tree ();
  1029.       init_lex ();
  1030.       init_rtl ();
  1031.       init_emit_once ();
  1032.       init_decl_processing ();
  1033.       init_optabs ();
  1034.       init_stmt ();
  1035.     }
  1036.   else
  1037.     {
  1038.       extern void reinit_lex_for_unexec ();
  1039.       main_input_filename = 0;
  1040.       reinit_lex_for_unexec ();
  1041.       reinit_search_statistics ();
  1042.     }
  1043.  
  1044. #ifdef FIELD_XREF
  1045.   if (field_xref) FIELD_xref_begin(input_filename);
  1046. #endif
  1047.  
  1048.   /* If rtl dump desired, open the output file.  */
  1049.   if (rtl_dump)
  1050.     {
  1051.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1052.       strcpy (dumpname, dump_base_name);
  1053.       strcat (dumpname, ".rtl");
  1054.       rtl_dump_file = fopen (dumpname, "w");
  1055.       if (rtl_dump_file == 0)
  1056.     pfatal_with_name (dumpname);
  1057.     }
  1058.  
  1059.   /* If jump_opt dump desired, open the output file.  */
  1060.   if (jump_opt_dump)
  1061.     {
  1062.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1063.       strcpy (dumpname, dump_base_name);
  1064.       strcat (dumpname, ".jump");
  1065.       jump_opt_dump_file = fopen (dumpname, "w");
  1066.       if (jump_opt_dump_file == 0)
  1067.     pfatal_with_name (dumpname);
  1068.     }
  1069.  
  1070.   /* If cse dump desired, open the output file.  */
  1071.   if (cse_dump)
  1072.     {
  1073.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1074.       strcpy (dumpname, dump_base_name);
  1075.       strcat (dumpname, ".cse");
  1076.       cse_dump_file = fopen (dumpname, "w");
  1077.       if (cse_dump_file == 0)
  1078.     pfatal_with_name (dumpname);
  1079.     }
  1080.  
  1081.   /* If loop dump desired, open the output file.  */
  1082.   if (loop_dump)
  1083.     {
  1084.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1085.       strcpy (dumpname, dump_base_name);
  1086.       strcat (dumpname, ".loop");
  1087.       loop_dump_file = fopen (dumpname, "w");
  1088.       if (loop_dump_file == 0)
  1089.     pfatal_with_name (dumpname);
  1090.     }
  1091.  
  1092.   /* If flow dump desired, open the output file.  */
  1093.   if (flow_dump)
  1094.     {
  1095.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1096.       strcpy (dumpname, dump_base_name);
  1097.       strcat (dumpname, ".flow");
  1098.       flow_dump_file = fopen (dumpname, "w");
  1099.       if (flow_dump_file == 0)
  1100.     pfatal_with_name (dumpname);
  1101.     }
  1102.  
  1103.   /* If combine dump desired, open the output file.  */
  1104.   if (combine_dump)
  1105.     {
  1106.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
  1107.       strcpy (dumpname, dump_base_name);
  1108.       strcat (dumpname, ".combine");
  1109.       combine_dump_file = fopen (dumpname, "w");
  1110.       if (combine_dump_file == 0)
  1111.     pfatal_with_name (dumpname);
  1112.     }
  1113.  
  1114.   /* If local_reg dump desired, open the output file.  */
  1115.   if (local_reg_dump)
  1116.     {
  1117.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1118.       strcpy (dumpname, dump_base_name);
  1119.       strcat (dumpname, ".lreg");
  1120.       local_reg_dump_file = fopen (dumpname, "w");
  1121.       if (local_reg_dump_file == 0)
  1122.     pfatal_with_name (dumpname);
  1123.     }
  1124.  
  1125.   /* If global_reg dump desired, open the output file.  */
  1126.   if (global_reg_dump)
  1127.     {
  1128.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1129.       strcpy (dumpname, dump_base_name);
  1130.       strcat (dumpname, ".greg");
  1131.       global_reg_dump_file = fopen (dumpname, "w");
  1132.       if (global_reg_dump_file == 0)
  1133.     pfatal_with_name (dumpname);
  1134.     }
  1135.  
  1136.   /* If jump2_opt dump desired, open the output file.  */
  1137.   if (jump2_opt_dump)
  1138.     {
  1139.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
  1140.       strcpy (dumpname, dump_base_name);
  1141.       strcat (dumpname, ".jump2");
  1142.       jump2_opt_dump_file = fopen (dumpname, "w");
  1143.       if (jump2_opt_dump_file == 0)
  1144.     pfatal_with_name (dumpname);
  1145.     }
  1146.  
  1147.   /* If dbr_sched dump desired, open the output file.  */
  1148.   if (dbr_sched_dump)
  1149.     {
  1150.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
  1151.       strcpy (dumpname, dump_base_name);
  1152.       strcat (dumpname, ".dbr");
  1153.       dbr_sched_dump_file = fopen (dumpname, "w");
  1154.       if (dbr_sched_dump_file == 0)
  1155.     pfatal_with_name (dumpname);
  1156.     }
  1157.  
  1158.   /* Open assembler code output file.  */
  1159.  
  1160.   if (! name_specified && asm_file_name == 0)
  1161.     asm_out_file = stdout;
  1162.   else
  1163.     {
  1164.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1165.       int len = strlen (dump_base_name);
  1166.       strcpy (dumpname, dump_base_name);
  1167.       if (len > 2 && ! strcmp (".c", dumpname + len - 2))
  1168.     dumpname[len - 2] = 0;
  1169.       else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
  1170.     dumpname[len - 2] = 0;
  1171.       else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
  1172.     dumpname[len - 3] = 0;
  1173.       strcat (dumpname, ".s");
  1174.       if (asm_file_name == 0)
  1175.     {
  1176.       asm_file_name = (char *) malloc (strlen (dumpname) + 1);
  1177.       strcpy (asm_file_name, dumpname);
  1178.     }
  1179.       if (!strcmp (asm_file_name, "-"))
  1180.     asm_out_file = stdout;
  1181.       else
  1182.     asm_out_file = fopen (asm_file_name, "w");
  1183.       if (asm_out_file == 0)
  1184.     pfatal_with_name (asm_file_name);
  1185.     }
  1186.  
  1187.   input_filename = name;
  1188.  
  1189.   /* the beginning of the file is a new line; check for # */
  1190.   /* With luck, we discover the real source file's name from that
  1191.      and put it in input_filename.  */
  1192.   ungetc (check_newline (), finput);
  1193.  
  1194.   /* If the input doesn't start with a #line, use the input name
  1195.      as the official input file name.  */
  1196.   if (main_input_filename == 0)
  1197.     main_input_filename = name;
  1198.  
  1199.   /* Put an entry on the input file stack for the main input file.  */
  1200.   input_file_stack
  1201.     = (struct file_stack *) xmalloc (sizeof (struct file_stack));
  1202.   input_file_stack->next = 0;
  1203.   input_file_stack->name = input_filename;
  1204.  
  1205.   if (!been_here_before)
  1206.     {
  1207.       ASM_FILE_START (asm_out_file);
  1208.  
  1209.       /* Output something to inform GDB that this compilation was by GCC.  */
  1210. #ifndef ASM_IDENTIFY_GCC
  1211.       fprintf (asm_out_file, "gcc_compiled.:\n");
  1212. #else
  1213.       ASM_IDENTIFY_GCC (asm_out_file);
  1214. #endif
  1215.  
  1216.     }
  1217.   else
  1218.     {
  1219.       /* Copy what we output during the first run into this asm file. */
  1220.       FILE *prev_file;
  1221.       int c;
  1222.       prev_file = fopen (previous_asm_file_name, "r");
  1223.       if (prev_file == 0)
  1224.     pfatal_with_name (previous_asm_file_name);
  1225. #ifndef VMS
  1226. #ifndef MASSCOMP
  1227.       if (Z_BUFSIZ(asm_out_file) != Z_BUFSIZ(prev_file))
  1228. #endif
  1229. #endif
  1230.     {
  1231.       while ((c = getc (prev_file)) != EOF)
  1232.         putc (c, asm_out_file);
  1233.     }
  1234. #ifndef VMS
  1235. #ifndef MASSCOMP
  1236.       else
  1237.     {
  1238.       /* Copy quickly.  */
  1239.       int dummy, size;
  1240.  
  1241.       fwrite (&dummy, 1, 1, asm_out_file);
  1242.       asm_out_file->_ptr = asm_out_file->_base;
  1243.       asm_out_file->_cnt = Z_BUFSIZ(asm_out_file);
  1244.       do
  1245.         {
  1246.           size = fread (asm_out_file->_base, 1, Z_BUFSIZ(asm_out_file), prev_file);
  1247.           asm_out_file->_ptr += size;
  1248.           asm_out_file->_cnt -= size;
  1249.           fflush (asm_out_file);
  1250.         }
  1251.       while (size == Z_BUFSIZ(asm_out_file));
  1252.     }
  1253. #endif
  1254. #endif
  1255.       fclose (prev_file);
  1256.     }
  1257.  
  1258. #if 0  /* This mode is discontinued.  */
  1259.   /* If GDB symbol table desired, open the GDB symbol output file.  */
  1260.   if (write_symbols == GDB_DEBUG)
  1261.     {
  1262.       register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
  1263.       int len = strlen (dump_base_name);
  1264.       strcpy (dumpname, dump_base_name);
  1265.       if (len > 2 && ! strcmp (".c", dumpname + len - 2))
  1266.     dumpname[len - 2] = 0;
  1267.       else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
  1268.     dumpname[len - 2] = 0;
  1269.       else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
  1270.     dumpname[len - 3] = 0;
  1271.       strcat (dumpname, ".sym");
  1272.       if (sym_file_name == 0)
  1273.     sym_file_name = dumpname;
  1274.       symout_init (sym_file_name, asm_out_file, main_input_filename);
  1275.     }
  1276. #endif /* 0 */
  1277.  
  1278.   /* If dbx symbol table desired, initialize writing it
  1279.      and output the predefined types.  */
  1280. #ifdef DBX_DEBUGGING_INFO
  1281.   if (write_symbols == DBX_DEBUG)
  1282.     {
  1283.       if (!been_here_before) 
  1284.     dbxout_init (asm_out_file, main_input_filename);
  1285.       else
  1286.     {
  1287.       extern void re_init_dbxout_for_unexec ();
  1288.       re_init_dbxout_for_unexec (asm_out_file, main_input_filename);
  1289.     }
  1290.     }
  1291. #endif
  1292. #ifdef SDB_DEBUGGING_INFO
  1293.   if (write_symbols == SDB_DEBUG)
  1294.     sdbout_init (asm_out_file, main_input_filename);
  1295. #endif
  1296.  
  1297.   /* Initialize yet another pass.  */
  1298.  
  1299.   if (!been_here_before)
  1300.     init_final (main_input_filename);
  1301.  
  1302.   start_time = gettime ();
  1303.  
  1304.   /* Call the parser, which parses the entire file
  1305.      (calling rest_of_compilation for each function).  */
  1306.  
  1307.   if (setjmp (toplevel) == 0)
  1308.     {
  1309.       if (yyparse () != 0)
  1310.     {
  1311.       if (errorcount == 0)
  1312.         {
  1313.           fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
  1314.           errorcount = 1;
  1315.         }
  1316.     }
  1317.  
  1318.       /* Compilation is now finished except for writing
  1319.      what's left of the symbol table output.  */
  1320.  
  1321.       parse_time += gettime () - start_time;
  1322.  
  1323.       parse_time -= integration_time;
  1324.       parse_time -= varconst_time;
  1325.     }
  1326.   else
  1327.     {
  1328.       /* Change by Bryan Boreham, Kewill, Sat Aug  5 19:05:44 1989.
  1329.      We'll be coming back later, so skip the finish.
  1330.      Modified by Michael Tiemann.  */
  1331.  
  1332.       /* Compilation is now finished except for now.  */
  1333.  
  1334.       parse_time += gettime () - start_time;
  1335.  
  1336.       parse_time -= integration_time;
  1337.       parse_time -= varconst_time;
  1338.  
  1339.       goto after_finish_compilation;
  1340.     }
  1341.  
  1342.   globals = getdecls ();
  1343.  
  1344.   /* Really define vars that have had only a tentative definition.
  1345.      Really output inline functions that must actually be callable
  1346.      and have not been output so far.  */
  1347.  
  1348.   {
  1349.     tree decl;
  1350.     for (decl = globals; decl; decl = TREE_CHAIN (decl))
  1351.       {
  1352.     if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
  1353.         && ! TREE_ASM_WRITTEN (decl))
  1354.       {
  1355.         /* Don't write out static consts, unless we needed
  1356.            to take their address for some reason.  */
  1357.         if (! TREE_READONLY (decl)
  1358.         || TREE_PUBLIC (decl)
  1359.         || TREE_ADDRESSABLE (decl)
  1360.         || TREE_ADDRESSABLE (DECL_NAME (decl)))
  1361.           rest_of_decl_compilation (decl, 0, 1, 1);
  1362.         /* Otherwise maybe mention them just for the debugger.  */
  1363. #ifdef DBX_DEBUGGING_INFO
  1364.         else if (DECL_INITIAL (decl) && write_symbols == DBX_DEBUG)
  1365.           TIMEVAR (varconst_time, dbxout_symbol (decl, 0));
  1366. #endif
  1367. #ifdef SDB_DEBUGGING_INFO
  1368.         else if (DECL_INITIAL (decl) && write_symbols == SDB_DEBUG)
  1369.           TIMEVAR (varconst_time, sdbout_symbol (decl, 0));
  1370. #endif
  1371.       }
  1372.     if (TREE_CODE (decl) == FUNCTION_DECL
  1373.         && ! TREE_ASM_WRITTEN (decl)
  1374.         && DECL_INITIAL (decl) != 0
  1375.         && (TREE_ADDRESSABLE (decl) || TREE_ADDRESSABLE (DECL_NAME (decl)))
  1376.         && ! TREE_EXTERNAL (decl))
  1377.       output_inline_function (decl);
  1378.  
  1379.     /* Warn about any function or variable
  1380.        declared static but not defined.  */
  1381.     if ((warn_unused || TREE_USED (decl) || TREE_USED (DECL_NAME (decl)))
  1382. /*        && TREE_CODE (decl) == FUNCTION_DECL  */
  1383.         && DECL_INITIAL (decl) == 0
  1384.         && TREE_EXTERNAL (decl)
  1385.         && ! TREE_PUBLIC (decl))
  1386.       warning_with_decl (decl, "`%s' declared `static' but never defined");
  1387.     /* Warn about static fns or vars defined but not used,
  1388.        but not about inline functions
  1389.        since unused inline statics is normal practice.  */
  1390.     if (warn_unused
  1391.         && (TREE_CODE (decl) == FUNCTION_DECL
  1392.         || TREE_CODE (decl) == VAR_DECL)
  1393.         && ! TREE_EXTERNAL (decl)
  1394.         && ! TREE_PUBLIC (decl)
  1395.         && ! TREE_USED (decl)
  1396.         && ! TREE_INLINE (decl)
  1397.         /* The TREE_USED bit for file-scope decls
  1398.            is kept in the identifier, to handle multiple
  1399.            external decls in different scopes.  */
  1400.         && ! TREE_USED (DECL_NAME (decl)))
  1401.       warning_with_decl (decl, "`%s' defined but not used");
  1402.       }
  1403.   }
  1404.  
  1405.   /* Do dbx symbols */
  1406. #ifdef DBX_DEBUGGING_INFO
  1407.   if (write_symbols == DBX_DEBUG)
  1408.     TIMEVAR (symout_time,
  1409.          {
  1410.            dbxout_tags (gettags ());
  1411.            dbxout_types (get_permanent_types ());
  1412.          });
  1413. #endif
  1414.  
  1415. #ifdef SDB_DEBUGGING_INFO
  1416.   if (write_symbols == SDB_DEBUG)
  1417.     TIMEVAR (symout_time,
  1418.          {
  1419.            tree decl;
  1420.            sdbout_tags (gettags ());
  1421.            sdbout_types (get_permanent_types ());
  1422.            /* Output first static file-scope vars, then global ones.  */
  1423.            for (decl = globals; decl; decl = TREE_CHAIN (decl))
  1424.          if (TREE_CODE (decl) == VAR_DECL && !TREE_PUBLIC (decl))
  1425.            sdbout_symbol (decl, 1);
  1426.            for (decl = globals; decl; decl = TREE_CHAIN (decl))
  1427.          if (TREE_CODE (decl) == VAR_DECL && TREE_PUBLIC (decl))
  1428.            sdbout_symbol (decl, 1);
  1429.          });
  1430. #endif
  1431.  
  1432. #if 0  /* This mode is discontinued */
  1433.   /* Do gdb symbols */
  1434.   if (write_symbols == GDB_DEBUG)
  1435.     TIMEVAR (symout_time,
  1436.          {
  1437.            struct stat statbuf;
  1438.            fstat (fileno (finput), &statbuf);
  1439.            symout_types (get_permanent_types ());
  1440.            symout_top_blocks (globals, gettags ());
  1441.            symout_finish (name, statbuf.st_ctime);
  1442.          });
  1443. #endif /* 0 */
  1444.  
  1445.   /* Output some stuff at end of file if nec.  */
  1446.  
  1447.   end_final (main_input_filename);
  1448.  
  1449. #ifdef ASM_FILE_END
  1450.   ASM_FILE_END (asm_out_file);
  1451. #endif
  1452.  
  1453.  after_finish_compilation:
  1454.  
  1455.   /* Close the dump files.  */
  1456.  
  1457.   if (rtl_dump)
  1458.     fclose (rtl_dump_file);
  1459.  
  1460.   if (jump_opt_dump)
  1461.     fclose (jump_opt_dump_file);
  1462.  
  1463.   if (cse_dump)
  1464.     fclose (cse_dump_file);
  1465.  
  1466.   if (loop_dump)
  1467.     fclose (loop_dump_file);
  1468.  
  1469.   if (flow_dump)
  1470.     fclose (flow_dump_file);
  1471.  
  1472.   if (combine_dump)
  1473.     {
  1474.       dump_combine_total_stats (combine_dump_file);
  1475.       fclose (combine_dump_file);
  1476.     }
  1477.  
  1478.   if (local_reg_dump)
  1479.     fclose (local_reg_dump_file);
  1480.  
  1481.   if (global_reg_dump)
  1482.     fclose (global_reg_dump_file);
  1483.  
  1484.   if (jump2_opt_dump)
  1485.     fclose (jump2_opt_dump_file);
  1486.  
  1487.   if (dbr_sched_dump)
  1488.     fclose (dbr_sched_dump_file);
  1489.  
  1490.   /* Close non-debugging input and output files.  Take special care to note
  1491.      whether fclose returns an error, since the pages might still be on the
  1492.      buffer chain while the file is open.  */
  1493.  
  1494.   fclose (finput);
  1495.   if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
  1496.     fatal_io_error (asm_file_name);
  1497.  
  1498.   /* Print the times.  */
  1499.  
  1500.   if (! quiet_flag)
  1501.     {
  1502.       fprintf (stderr,"\n");
  1503.       print_time ("parse", parse_time);
  1504.       print_time ("integration", integration_time);
  1505.       print_time ("jump", jump_time);
  1506.       print_time ("cse", cse_time);
  1507.       print_time ("loop", loop_time);
  1508.       print_time ("flow", flow_time);
  1509.       print_time ("combine", combine_time);
  1510.       print_time ("local-alloc", local_alloc_time);
  1511.       print_time ("global-alloc", global_alloc_time);
  1512.       print_time ("dbranch", dbr_sched_time);
  1513.       print_time ("final", final_time);
  1514.       print_time ("varconst", varconst_time);
  1515.       print_time ("symout", symout_time);
  1516.       print_time ("dump", dump_time);
  1517.     }
  1518. }
  1519.  
  1520. /* This is called from finish_decl (within yyparse)
  1521.    for each declaration of a function or variable.
  1522.    This does nothing for automatic variables.
  1523.    Otherwise, it sets up the RTL and outputs any assembler code
  1524.    (label definition, storage allocation and initialization).
  1525.  
  1526.    DECL is the declaration.  If ASMSPEC is nonzero, it specifies
  1527.    the assembler symbol name to be used.  TOP_LEVEL is nonzero
  1528.    if this declaration is not within a function.  */
  1529.  
  1530. void
  1531. rest_of_decl_compilation (decl, asmspec, top_level, at_end)
  1532.      tree decl;
  1533.      char *asmspec;
  1534.      int top_level;
  1535.      int at_end;
  1536. {
  1537.   /* Declarations of variables, and of functions defined elsewhere.  */
  1538.  
  1539.   if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
  1540.     TIMEVAR (varconst_time,
  1541.          {
  1542.            make_decl_rtl (decl, asmspec, top_level);
  1543.            /* Don't output anything
  1544.           when a tentative file-scope definition is seen.
  1545.           But at end of compilation, do output code for them.  */
  1546.            if (! (! at_end && top_level
  1547.               && (DECL_INITIAL (decl) == 0
  1548.               || DECL_INITIAL (decl) == error_mark_node)))
  1549.          assemble_variable (decl, top_level, write_symbols, at_end);
  1550.          });
  1551.   else if (TREE_REGDECL (decl) && asmspec != 0)
  1552.     {
  1553.       if (decode_reg_name (asmspec) >= 0)
  1554.     {
  1555.       if (TREE_CODE (decl) == PARM_DECL)
  1556.         error ("parameter cannot have special register declaration");
  1557.       else
  1558.         {
  1559.           DECL_RTL (decl) = 0;
  1560.           make_decl_rtl (decl, asmspec, top_level);
  1561.         }
  1562.     }
  1563.       else
  1564.     error ("invalid register name `%s' for register variable", asmspec);
  1565.     }
  1566. #ifdef DBX_DEBUGGING_INFO
  1567.   else if (write_symbols == DBX_DEBUG && TREE_CODE (decl) == TYPE_DECL)
  1568.     TIMEVAR (varconst_time, dbxout_symbol (decl, 0));
  1569. #endif
  1570. #ifdef SDB_DEBUGGING_INFO
  1571.   else if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == TYPE_DECL)
  1572.     TIMEVAR (varconst_time, sdbout_symbol (decl, 0));
  1573. #endif
  1574.  
  1575.   if (top_level)
  1576.     {
  1577. #if 0  /* This mode is discontinued */
  1578.       if (write_symbols == GDB_DEBUG)
  1579.     {
  1580.       TIMEVAR (symout_time,
  1581.            {
  1582.              /* The initizations make types when they contain
  1583.             string constants.  The types are on the temporary
  1584.             obstack, so output them now before they go away.  */
  1585.              symout_types (get_temporary_types ());
  1586.            });
  1587.     }
  1588.       else
  1589. #endif /* 0 */
  1590.     /* Clean out the temporary type list, since the types will go away.  */
  1591.     get_temporary_types ();
  1592.     }
  1593. }
  1594.  
  1595. /* This is called from finish_function (within yyparse)
  1596.    after each top-level definition is parsed.
  1597.    It is supposed to compile that function or variable
  1598.    and output the assembler code for it.
  1599.    After we return, the tree storage is freed.  */
  1600.  
  1601. void
  1602. rest_of_compilation (decl)
  1603.      tree decl;
  1604. {
  1605.   register rtx insns;
  1606.   int start_time = gettime ();
  1607.   int tem;
  1608.  
  1609.   /* If we are reconsidering an inline function
  1610.      at the end of compilation, skip the stuff for making it inline.  */
  1611.  
  1612.   if (DECL_SAVED_INSNS (decl) == 0)
  1613.     {
  1614.       int specd = TREE_INLINE (decl);
  1615.       char *lose;
  1616.  
  1617.       if (specd || flag_inline_functions)
  1618.     {
  1619.       lose = function_cannot_inline_p (decl);
  1620.       if (lose)
  1621.         {
  1622.           if (warn_inline && specd)
  1623.         warning_with_decl (decl, lose);
  1624.           TREE_INLINE (decl) = 0;
  1625.         }
  1626.     }
  1627.       else
  1628.     lose = "compiler error";
  1629.  
  1630.       insns = get_insns ();
  1631.  
  1632.       /* Dump the rtl code if we are dumping rtl.  */
  1633.  
  1634.       if (rtl_dump)
  1635.     TIMEVAR (dump_time,
  1636.          {
  1637.            fprintf (rtl_dump_file, "\n;; Function %s\n\n",
  1638.                 IDENTIFIER_POINTER (DECL_NAME (decl)));
  1639.            if (lose == 0)
  1640.              fprintf (rtl_dump_file, ";; (integrable)\n\n");
  1641.            print_rtl (rtl_dump_file, insns);
  1642.            fflush (rtl_dump_file);
  1643.          });
  1644.  
  1645.       /* If function is inline, and we don't yet know whether to
  1646.      compile it by itself, defer decision till end of compilation.
  1647.      finish_compilation will call rest_of_compilation again
  1648.      for those functions that need to be output.  */
  1649.  
  1650.       if (TREE_INLINE (decl)
  1651.       && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
  1652.            && ! flag_keep_inline_functions)
  1653.           || TREE_EXTERNAL (decl)))
  1654.     {
  1655.       save_for_outline (decl);
  1656.       goto exit_rest_of_compilation;
  1657.     }
  1658.  
  1659.       /* If we have to compile the function now, save its rtl
  1660.      so that its compilation will not affect what others get.  */
  1661.       if (TREE_INLINE (decl))
  1662.     TIMEVAR (integration_time, save_for_inline (decl));
  1663.     }
  1664.  
  1665.   TREE_ASM_WRITTEN (decl) = 1;
  1666.  
  1667.   if (rtl_dump_and_exit || flag_syntax_only)
  1668.     {
  1669.       get_temporary_types ();
  1670.       goto exit_rest_of_compilation;
  1671.     }
  1672.  
  1673.   insns = get_insns ();
  1674.  
  1675.   /* Copy any shared structure that should not be shared.  */
  1676.  
  1677.   unshare_all_rtl (insns);
  1678.  
  1679.   /* See if we have allocated stack slots that are not directly addressable.
  1680.      If so, scan all the insns and create explicit address computation
  1681.      for all references to such slots.  */
  1682. /*   fixup_stack_slots (); */
  1683.  
  1684.   /* Do jump optimization the first time, if -opt.
  1685.      Also do it if -W, but in that case it doesn't change the rtl code,
  1686.      it only computes whether control can drop off the end of the function.  */
  1687.  
  1688.   if (optimize || extra_warnings || warn_return_type
  1689.       /* If function is `volatile', we should warn if it tries to return.  */
  1690.       || TREE_THIS_VOLATILE (decl))
  1691.     TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
  1692.  
  1693.   /* Dump rtl code after jump, if we are doing that.  */
  1694.  
  1695.   if (jump_opt_dump)
  1696.     TIMEVAR (dump_time,
  1697.          {
  1698.            fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
  1699.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1700.            print_rtl (jump_opt_dump_file, insns);
  1701.            fflush (jump_opt_dump_file);
  1702.          });
  1703.  
  1704.   /* Perform common subexpression elimination.
  1705.      Nonzero value from `cse_main' means that jumps were simplified
  1706.      and some code may now be unreachable, so do
  1707.      jump optimization again.  */
  1708.  
  1709.   if (cse_dump)
  1710.     TIMEVAR (dump_time,
  1711.          {
  1712.            fprintf (cse_dump_file, "\n;; Function %s\n\n",
  1713.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1714.          });
  1715.  
  1716.   if (optimize)
  1717.     {
  1718.       TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 0));
  1719.  
  1720.       TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (), cse_dump_file));
  1721.  
  1722.       if (tem)
  1723.     TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
  1724.     }
  1725.  
  1726.   /* Dump rtl code after cse, if we are doing that.  */
  1727.  
  1728.   if (cse_dump)
  1729.     TIMEVAR (dump_time,
  1730.          {
  1731.            print_rtl (cse_dump_file, insns);
  1732.            fflush (cse_dump_file);
  1733.          });
  1734.  
  1735.   if (loop_dump)
  1736.     TIMEVAR (dump_time,
  1737.          {
  1738.            fprintf (loop_dump_file, "\n;; Function %s\n\n",
  1739.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1740.          });
  1741.  
  1742.   /* Move constant computations out of loops.  */
  1743.  
  1744.   if (optimize)
  1745.     {
  1746.       TIMEVAR (loop_time,
  1747.            {
  1748.          reg_scan (insns, max_reg_num (), 1);
  1749.          loop_optimize (insns, loop_dump ? loop_dump_file : 0);
  1750.            });
  1751.     }
  1752.  
  1753.   /* Dump rtl code after loop opt, if we are doing that.  */
  1754.  
  1755.   if (loop_dump)
  1756.     TIMEVAR (dump_time,
  1757.          {
  1758.            print_rtl (loop_dump_file, insns);
  1759.            fflush (loop_dump_file);
  1760.          });
  1761.  
  1762.   /* Now we choose between stupid (pcc-like) register allocation
  1763.      (if we got the -noreg switch and not -opt)
  1764.      and smart register allocation.  */
  1765.  
  1766.   if (optimize)            /* Stupid allocation probably won't work */
  1767.     obey_regdecls = 0;        /* if optimizations being done.  */
  1768.  
  1769.   regclass_init ();
  1770.  
  1771.   /* Print function header into flow dump now
  1772.      because doing the flow analysis makes some of the dump.  */
  1773.  
  1774.   if (flow_dump)
  1775.     TIMEVAR (dump_time,
  1776.          {
  1777.            fprintf (flow_dump_file, "\n;; Function %s\n\n",
  1778.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1779.          });
  1780.  
  1781.   if (obey_regdecls)
  1782.     {
  1783.       TIMEVAR (flow_time,
  1784.            {
  1785.          regclass (insns, max_reg_num ());
  1786.          stupid_life_analysis (insns, max_reg_num (),
  1787.                        flow_dump_file);
  1788.            });
  1789.     }
  1790.   else
  1791.     {
  1792.       /* Do control and data flow analysis,
  1793.      and write some of the results to dump file.  */
  1794.  
  1795.       TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
  1796.                      flow_dump_file));
  1797.       if (extra_warnings)
  1798.     uninitialized_vars_warning (DECL_INITIAL (decl));
  1799.     }
  1800.  
  1801.   /* Dump rtl after flow analysis.  */
  1802.  
  1803.   if (flow_dump)
  1804.     TIMEVAR (dump_time,
  1805.          {
  1806.            print_rtl (flow_dump_file, insns);
  1807.            fflush (flow_dump_file);
  1808.          });
  1809.  
  1810.   /* If -opt, try combining insns through substitution.  */
  1811.  
  1812.   if (optimize)
  1813.     TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
  1814.  
  1815.   /* Dump rtl code after insn combination.  */
  1816.  
  1817.   if (combine_dump)
  1818.     TIMEVAR (dump_time,
  1819.          {
  1820.            fprintf (combine_dump_file, "\n;; Function %s\n\n",
  1821.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1822.            dump_combine_stats (combine_dump_file);
  1823.            print_rtl (combine_dump_file, insns);
  1824.            fflush (combine_dump_file);
  1825.          });
  1826.  
  1827.   /* Unless we did stupid register allocation,
  1828.      allocate pseudo-regs that are used only within 1 basic block.  */
  1829.  
  1830.   if (!obey_regdecls)
  1831.     TIMEVAR (local_alloc_time,
  1832.          {
  1833.            regclass (insns, max_reg_num ());
  1834.            local_alloc ();
  1835.          });
  1836.  
  1837.   /* Dump rtl code after allocating regs within basic blocks.  */
  1838.  
  1839.   if (local_reg_dump)
  1840.     TIMEVAR (dump_time,
  1841.          {
  1842.            fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
  1843.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1844.            dump_flow_info (local_reg_dump_file);
  1845.            dump_local_alloc (local_reg_dump_file);
  1846.            print_rtl (local_reg_dump_file, insns);
  1847.            fflush (local_reg_dump_file);
  1848.          });
  1849.  
  1850.   if (global_reg_dump)
  1851.     TIMEVAR (dump_time,
  1852.          fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
  1853.               IDENTIFIER_POINTER (DECL_NAME (decl))));
  1854.  
  1855.   /* Unless we did stupid register allocation,
  1856.      allocate remaining pseudo-regs, then do the reload pass
  1857.      fixing up any insns that are invalid.  */
  1858.  
  1859.   TIMEVAR (global_alloc_time,
  1860.        {
  1861.          if (!obey_regdecls)
  1862.            global_alloc (global_reg_dump ? global_reg_dump_file : 0);
  1863.          else
  1864.            reload (insns, 0,
  1865.                global_reg_dump ? global_reg_dump_file : 0);
  1866.        });
  1867.  
  1868.   if (global_reg_dump)
  1869.     TIMEVAR (dump_time,
  1870.          {
  1871.            dump_global_regs (global_reg_dump_file);
  1872.            print_rtl (global_reg_dump_file, insns);
  1873.            fflush (global_reg_dump_file);
  1874.          });
  1875.  
  1876.   rtx_equal_function_value_matters = 1;
  1877.   reload_completed = 1;
  1878.  
  1879.   /* One more attempt to remove jumps to .+1
  1880.      left by dead-store-elimination.
  1881.      Also do cross-jumping this time
  1882.      and delete no-op move insns.  */
  1883.  
  1884.   if (optimize)
  1885.     {
  1886.       TIMEVAR (jump_time, jump_optimize (insns, 1, 1));
  1887.     }
  1888.  
  1889.   /* Dump rtl code after jump, if we are doing that.  */
  1890.  
  1891.   if (jump2_opt_dump)
  1892.     TIMEVAR (dump_time,
  1893.          {
  1894.            fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
  1895.             IDENTIFIER_POINTER (DECL_NAME (decl)));
  1896.            print_rtl (jump2_opt_dump_file, insns);
  1897.            fflush (jump2_opt_dump_file);
  1898.          });
  1899.  
  1900.   /* If a scheduling pass for delayed branches is to be done,
  1901.      call the scheduling code. */
  1902.  
  1903. #ifdef HAVE_DELAYED_BRANCH
  1904.   if (optimize && flag_delayed_branch)
  1905.     {
  1906.       TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
  1907.       if (dbr_sched_dump)
  1908.     {
  1909.       TIMEVAR (dump_time,
  1910.          {
  1911.            fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
  1912.                 IDENTIFIER_POINTER (DECL_NAME (decl)));
  1913.            print_rtl (dbr_sched_dump_file, insns);
  1914.            fflush (dbr_sched_dump_file);
  1915.          });
  1916.     }
  1917.     }
  1918. #endif
  1919.  
  1920.   /* Now turn the rtl into assembler code.  */
  1921.  
  1922.   TIMEVAR (final_time,
  1923.        {
  1924.          assemble_function (decl);
  1925.          final_start_function (insns, asm_out_file,
  1926.                    write_symbols, optimize);
  1927.          final (insns, asm_out_file,
  1928.             write_symbols, optimize, 0);
  1929.          final_end_function (insns, asm_out_file,
  1930.                  write_symbols, optimize);
  1931.          fflush (asm_out_file);
  1932.        });
  1933.  
  1934. #if 0  /* This mode is discontinued */
  1935.   /* Write GDB symbols if requested */
  1936.  
  1937.   if (write_symbols == GDB_DEBUG)
  1938.     {
  1939.       TIMEVAR (symout_time,
  1940.            {
  1941.          symout_types (get_permanent_types ());
  1942.          symout_types (get_temporary_types ());
  1943.  
  1944.          DECL_BLOCK_SYMTAB_ADDRESS (decl)
  1945.            = symout_function (DECL_INITIAL (decl),
  1946.                       DECL_ARGUMENTS (decl), 0);
  1947.          symout_function_end ();
  1948.            });
  1949.     }
  1950.   else
  1951. #endif /* 0 */
  1952.     get_temporary_types ();
  1953.  
  1954.   /* Write DBX symbols if requested */
  1955.  
  1956. #ifdef DBX_DEBUGGING_INFO
  1957.   if (write_symbols == DBX_DEBUG)
  1958.     TIMEVAR (symout_time, dbxout_function (decl));
  1959. #endif
  1960.  
  1961.  exit_rest_of_compilation:
  1962.  
  1963.   rtx_equal_function_value_matters = 0;
  1964.   reload_completed = 0;
  1965.  
  1966.   /* Clear out the real_constant_chain before some of the rtx's
  1967.      it runs through become garbage.  */
  1968.  
  1969.   clear_const_double_mem ();
  1970.  
  1971.   /* The parsing time is all the time spent in yyparse
  1972.      *except* what is spent in this function.  */
  1973.  
  1974.   parse_time -= gettime () - start_time;
  1975. }
  1976.  
  1977. #ifdef sun
  1978. #include <sys/mman.h>
  1979. /* Hacky routine to read back entire data segment saved earlier. 
  1980.    Michael Tiemann (tiemann@cygnus.com).  */
  1981.  
  1982. void undump_data (path, name)
  1983.      char *path, *name;
  1984. {
  1985.   extern char *rindex ();
  1986.   int file;
  1987.   long file_size;
  1988.   extern int my_edata;
  1989.   char *data;
  1990.  
  1991.   if ((file = open (name, O_RDONLY)) == -1)
  1992.     {
  1993.       char buf[256], *p;
  1994.       strcpy (buf, path);
  1995.       p = rindex (buf, '/');
  1996.       if (p)
  1997.     {
  1998.       strcpy (p+1, name);
  1999.       file = open (buf, O_RDONLY);
  2000.     }
  2001.     }
  2002.   if (file == -1)
  2003.     {
  2004.       perror(name);
  2005.       exit (-1);
  2006.     }
  2007.  
  2008.   file_size = lseek (file, 0L, SEEK_END);
  2009.   brk ((char*)(&my_edata) + file_size);
  2010.  
  2011.   data = (char *)((int)&my_edata&~(getpagesize()-1));
  2012.   if ((int)mmap (data, file_size, PROT_READ|PROT_WRITE,
  2013.          MAP_PRIVATE|MAP_FIXED, file, 0) < 0)
  2014.     {
  2015.       perror (name);
  2016.       exit (-1);
  2017.     }
  2018. }
  2019. #else
  2020. /* Hacky routine to read back entire data segment saved earlier. 
  2021.    Bryan Boreham (bryan@kewill.uucp)    */
  2022.  
  2023. void undump_data (path, name)
  2024.      char *name;
  2025. {
  2026.   int file;
  2027.   long file_size;
  2028.   extern int my_edata;
  2029.   char buf[256];
  2030.  
  2031.   strcpy (buf, "/usr/local/lib/");
  2032.   strcat (buf, name);
  2033.  
  2034.   if ((file = open(name, O_RDONLY)) == -1)
  2035.     if ((file = open(buf, O_RDONLY)) == -1)
  2036.       {
  2037.     perror(name);
  2038.     return;
  2039.       }
  2040.   file_size = lseek(file, 0L, SEEK_END);
  2041.   lseek(file, 0L, SEEK_SET);
  2042.   brk((char*)((int)&my_edata&~(getpagesize()-1)) + file_size);
  2043.   if (read (file, &my_edata, file_size) != file_size)
  2044.     perror(name);
  2045. }
  2046. #endif
  2047.  
  2048. /* Entry point of c++.  Decode command args, then call compile_file.
  2049.    Exit code is 35 if can't open files, 34 if fatal error,
  2050.    33 if had nonfatal errors, else success.  */
  2051.  
  2052. int
  2053. main (argc, argv, envp)
  2054.      int argc;
  2055.      char **argv;
  2056.      char **envp;
  2057. {
  2058.   register int i;
  2059.   char *filename = 0;
  2060.   int print_mem_flag = 0;
  2061.   char *p;
  2062.  
  2063.   /* save in case md file wants to emit args as a comment.  */
  2064.   save_argc = argc;
  2065.   save_argv = argv;
  2066.  
  2067.   p = argv[0] + strlen (argv[0]);
  2068.   while (p != argv[0] && p[-1] != '/') --p;
  2069.   progname = p;
  2070.  
  2071.   /* Change by Bryan Boreham, Kewill, Sun Aug  6 13:42:47 1989.
  2072.      Stuff for unexec'ing    */
  2073.   dump_source_name = argv[0];
  2074.   asm_file_name = (char*) 0;
  2075.   
  2076. #ifdef RLIMIT_STACK
  2077.   /* Get rid of any avoidable limit on stack size.  */
  2078.   {
  2079.     struct rlimit rlim;
  2080.  
  2081.     /* Set the stack limit huge so that alloca does not fail. */
  2082.     getrlimit (RLIMIT_STACK, &rlim);
  2083.     rlim.rlim_cur = rlim.rlim_max;
  2084.     setrlimit (RLIMIT_STACK, &rlim);
  2085.   }
  2086. #endif /* RLIMIT_STACK */
  2087.  
  2088.   signal (SIGFPE, float_signal);
  2089.  
  2090.   signal (SIGPIPE, pipe_closed);
  2091.  
  2092.   decl_printable_name = decl_name;
  2093.   lang_expand_expr = fancy_abort;
  2094.  
  2095.   /* Initialize whether `char' is signed.  */
  2096.   flag_signed_char = DEFAULT_SIGNED_CHAR;
  2097. #ifdef DEFAULT_SHORT_ENUMS
  2098.   /* Initialize how much space enums occupy, by default.  */
  2099.   flag_short_enums = DEFAULT_SHORT_ENUMS;
  2100. #endif
  2101.  
  2102.   /* This is zeroed by -O.  */
  2103.   obey_regdecls = 1;
  2104.  
  2105.   /* Initialize register usage now so switches may override.  */
  2106.   init_reg_sets ();
  2107.  
  2108.   target_flags = 0;
  2109.   set_target_switch ("");
  2110.  
  2111.   for (i = 1; i < argc; i++)
  2112.     {
  2113.       if (argv[i][0] == '-' && argv[i][1] != 0)
  2114.     {
  2115.       register char *str = argv[i] + 1;
  2116.       if (str[0] == 'Y')
  2117.         str++;
  2118.  
  2119.       if (str[0] == 'm')
  2120.         set_target_switch (&str[1]);
  2121.       else if (!strcmp (str, "dumpbase"))
  2122.         {
  2123.           dump_base_name = argv[++i];
  2124.         }
  2125.       else if (str[0] == 'd')
  2126.         {
  2127.           register char *p = &str[1];
  2128.           while (*p)
  2129.         switch (*p++)
  2130.           {
  2131.           case 'c':
  2132.             combine_dump = 1;
  2133.             break;
  2134.           case 'd':
  2135.             dbr_sched_dump = 1;
  2136.             break;
  2137.           case 'f':
  2138.             flow_dump = 1;
  2139.             break;
  2140.           case 'g':
  2141.             global_reg_dump = 1;
  2142.             break;
  2143.           case 'j':
  2144.             jump_opt_dump = 1;
  2145.             break;
  2146.           case 'J':
  2147.             jump2_opt_dump = 1;
  2148.             break;
  2149.           case 'l':
  2150.             local_reg_dump = 1;
  2151.             break;
  2152.           case 'L':
  2153.             loop_dump = 1;
  2154.             break;
  2155.           case 'm':
  2156.             print_mem_flag = 1;
  2157.             break;
  2158.           case 'r':
  2159.             rtl_dump = 1;
  2160.             break;
  2161.           case 's':
  2162.             cse_dump = 1;
  2163.             break;
  2164.           case 'y':
  2165.             yydebug = 1;
  2166.             break;
  2167.           case 'x':
  2168.             rtl_dump_and_exit = 1;
  2169.             break;
  2170.           }
  2171.         }
  2172.       else if (str[0] == 'f')
  2173.         {
  2174.           int j;
  2175.           register char *p = &str[1];
  2176.           int found = 0;
  2177.  
  2178.           /* Some kind of -f option.
  2179.          P's value is the option sans `-f'.
  2180.          Search for it in the table of options.  */
  2181.  
  2182.           for (j = 0;
  2183.            !found && j < sizeof (f_options) / sizeof (f_options[0]);
  2184.            j++)
  2185.         {
  2186.           if (!strcmp (p, f_options[j].string))
  2187.             {
  2188.               *f_options[j].variable = f_options[j].on_value;
  2189.               /* A goto here would be cleaner,
  2190.              but breaks the vax pcc.  */
  2191.               found = 1;
  2192.             }
  2193.           if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
  2194.               && ! strcmp (p+3, f_options[j].string))
  2195.             {
  2196.               *f_options[j].variable = ! f_options[j].on_value;
  2197.               found = 1;
  2198.             }
  2199.         }
  2200.  
  2201.           if (found)
  2202.         ;
  2203.           else if (!strncmp (p, "undump-", 7))
  2204.         undump_data (argv[0], &p[7]);
  2205.           else if (!strncmp (p, "fixed-", 6))
  2206.         fix_register (&p[6], 1, 1);
  2207.           else if (!strncmp (p, "call-used-", 10))
  2208.         fix_register (&p[10], 0, 1);
  2209.           else if (!strncmp (p, "call-saved-", 11))
  2210.         fix_register (&p[11], 0, 0);
  2211.           else if (! lang_decode_option (argv[i]))
  2212.         error ("Invalid option `%s'", argv[i]);
  2213.         }
  2214.       else if (!strcmp (str, "noreg"))
  2215.         ;
  2216.       else if (!strcmp (str, "opt"))
  2217.         optimize = 1, obey_regdecls = 0;
  2218.       else if (!strcmp (str, "O"))
  2219.         optimize = 1, obey_regdecls = 0;
  2220.       else if (!strcmp (str, "pedantic"))
  2221.         pedantic = 1;
  2222.       else if (lang_decode_option (argv[i]))
  2223.         ;
  2224.       else if (!strcmp (str, "quiet"))
  2225.         quiet_flag = 1;
  2226.       else if (!strcmp (str, "version"))
  2227.         {
  2228.           extern char *version_string, *language_string;
  2229.           fprintf (stderr, "%s version %s", language_string, version_string);
  2230. #ifdef TARGET_VERSION
  2231.           TARGET_VERSION;
  2232. #endif
  2233. #ifdef __GNUC__
  2234. #ifndef __VERSION__
  2235. #define __VERSION__ "[unknown]"
  2236. #endif
  2237.           fprintf (stderr, " compiled by GNU C version %s.\n", __VERSION__);
  2238. #else
  2239.           fprintf (stderr, " compiled by CC.\n");
  2240. #endif
  2241.           print_target_switch_defaults ();
  2242.         }
  2243.       else if (!strcmp (str, "w"))
  2244.         inhibit_warnings = 1;
  2245.       else if (!strcmp (str, "W"))
  2246.         extra_warnings = 1;
  2247.       else if (!strcmp (str, "Wunused"))
  2248.         warn_unused = 1;
  2249.       else if (!strcmp (str, "Wshadow"))
  2250.         warn_shadow = 1;
  2251.       else if (!strcmp (str, "Wswitch"))
  2252.         warn_switch = 1;
  2253.       else if (!strcmp (str, "Wconversion"))
  2254.         warn_conversion = 1;
  2255.       else if (!strncmp (str, "Wid-clash-", 10))
  2256.         {
  2257.           char *endp = str + 10;
  2258.  
  2259.           while (*endp)
  2260.         {
  2261.           if (*endp >= '0' && *endp <= '9')
  2262.             endp++;
  2263.           else
  2264.             error ("Invalid option `%s'", argv[i]);
  2265.         }
  2266.           warn_id_clash = 1;
  2267.           id_clash_len = atoi (str + 10);
  2268.         }
  2269.       else if (!strcmp (str, "Winline"))
  2270.         warn_inline = 1;
  2271.       else if (!strcmp (str, "p"))
  2272.         profile_flag = 1;
  2273.       else if (!strcmp (str, "a"))
  2274.         {
  2275. #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
  2276.           warning ("`-a' option (basic block profile) not supported");
  2277. #else
  2278.           profile_block_flag = 1;
  2279. #endif
  2280.         }
  2281. #if 0
  2282.       else if (!strcmp (str, "gg"))
  2283.         write_symbols = GDB_DEBUG;
  2284. #endif
  2285. #ifdef DBX_DEBUGGING_INFO
  2286.       else if (!strcmp (str, "g0"))
  2287.         write_symbols = DBX_DEBUG;
  2288.       else if (!strcmp (str, "G0"))
  2289.         write_symbols = DBX_DEBUG;
  2290. #ifdef SDB_DEBUGGING_INFO
  2291.       else if (!strcmp (str, "gsdb"))
  2292.         write_symbols = SDB_DEBUG;
  2293. #endif
  2294.       else if (!strcmp (str, "g"))
  2295.         {
  2296.           write_symbols = DBX_DEBUG;
  2297.           use_gdb_dbx_extensions = 1;
  2298.         }
  2299.       else if (!strcmp (str, "G"))
  2300.         {
  2301.           write_symbols = DBX_DEBUG;
  2302.           use_gdb_dbx_extensions = 1;
  2303.         }
  2304. #endif                /* DBX_DEBUGGING_INFO */
  2305. #ifdef SDB_DEBUGGING_INFO
  2306.       else if (!strcmp (str, "g"))
  2307.         write_symbols = SDB_DEBUG;
  2308.       else if (!strcmp (str, "G"))
  2309.         write_symbols = SDB_DEBUG;
  2310.       else if (!strcmp (str, "g0"))
  2311.         write_symbols = SDB_DEBUG;
  2312.       else if (!strcmp (str, "G0"))
  2313.         write_symbols = SDB_DEBUG;
  2314.       else if (!strcmp (str, "gsdb"))
  2315.         write_symbols = SDB_DEBUG;
  2316. #endif /* SDB_DEBUGGING_INFO */
  2317. #if defined(ASM_OUTPUT_SOURCE_FILENAME) && defined(ASM_OUTPUT_SOURCE_LINE)
  2318.       else if (!strcmp (str, "gline"))
  2319.         write_symbols = LINENO_DEBUG;
  2320. #endif
  2321. #if 0
  2322.       else if (!strcmp (str, "symout"))
  2323.         {
  2324.           if (write_symbols == NO_DEBUG)
  2325.         write_symbols = GDB_DEBUG;
  2326.           sym_file_name = argv[++i];
  2327.         }
  2328. #endif                /* 0 */
  2329.       else if (!strcmp (str, "o"))
  2330.         {
  2331.           asm_file_name = argv[++i];
  2332.         }
  2333. #ifdef FIELD_XREF
  2334.       else if (!strcmp(str,"xref"))
  2335.         field_xref = 1;
  2336. #endif
  2337.       else
  2338.         error ("Invalid option `%s'", argv[i]);
  2339.     }
  2340.       else if (argv[i][0] == '+')
  2341.     {
  2342.       if (lang_decode_option (argv[i]))
  2343.         ;
  2344.       else
  2345.         error ("Invalid option `%s'", argv[i]);
  2346.     }
  2347.       else
  2348.     filename = argv[i];
  2349.     }
  2350. #ifdef OVERRIDE_OPTIONS
  2351.   /* Some machines may reject certain combinations of options.  */
  2352.   OVERRIDE_OPTIONS;
  2353. #endif
  2354.  
  2355.   /* Now that register usage is specified, convert it to HARD_REG_SETs.  */
  2356.   init_reg_sets_1 ();
  2357.  
  2358.   compile_file (filename);
  2359.  
  2360. #ifndef USG
  2361. #ifndef VMS
  2362.   if (print_mem_flag)
  2363.     {
  2364.       extern char **environ;
  2365.       char *lim = (char *) sbrk (0);
  2366.  
  2367.       fprintf (stderr, "Data size %d.\n",
  2368.            (int) lim - (int) &environ);
  2369.       fflush (stderr);
  2370.  
  2371.       system ("ps v");
  2372.     }
  2373. #endif /* not VMS */
  2374. #endif /* not USG */
  2375.  
  2376. #ifdef FIELD_XREF
  2377.   FIELD_xref_end(errorcount+sorrycount);
  2378. #endif
  2379.  
  2380.   if (errorcount)
  2381.     exit (FATAL_EXIT_CODE);
  2382.   if (sorrycount)
  2383.     exit (FATAL_EXIT_CODE);
  2384.   exit (SUCCESS_EXIT_CODE);
  2385.   return 34;
  2386. }
  2387.  
  2388. /* Decode -m switches.  */
  2389.  
  2390. /* Here is a table, controlled by the tm-...h file, listing each -m switch
  2391.    and which bits in `target_switches' it should set or clear.
  2392.    If VALUE is positive, it is bits to set.
  2393.    If VALUE is negative, -VALUE is bits to clear.
  2394.    (The sign bit is not used so there is no confusion.)  */
  2395.  
  2396. struct {char *name; int value;} target_switches []
  2397.   = TARGET_SWITCHES;
  2398.  
  2399. /* Decode the switch -mNAME.  */
  2400.  
  2401. void
  2402. set_target_switch (name)
  2403.      char *name;
  2404. {
  2405.   register int j;
  2406.   int valid = 0;
  2407.  
  2408.   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
  2409.     if (!strcmp (target_switches[j].name, name))
  2410.       {
  2411.     if (target_switches[j].value < 0)
  2412.       target_flags &= ~-target_switches[j].value;
  2413.     else
  2414.       target_flags |= target_switches[j].value;
  2415.     valid = 1;
  2416.       }
  2417.  
  2418.   if (!valid)
  2419.     error ("Invalid option `%s'", name);
  2420. }
  2421.  
  2422. /* Print default target switches for -version.  */
  2423.  
  2424. void
  2425. print_target_switch_defaults ()
  2426. {
  2427.   register int j;
  2428.   register int mask = TARGET_DEFAULT;
  2429.  
  2430.   fprintf (stderr, "default target switches:");
  2431.   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
  2432.     if (target_switches[j].name[0] != '\0'
  2433.     && target_switches[j].value > 0
  2434.     && (target_switches[j].value & mask) == target_switches[j].value)
  2435.       fprintf (stderr, " -m%s", target_switches[j].name);
  2436.  
  2437.   fprintf (stderr, "\n");
  2438. }
  2439.